package com.xlobo.api.fund.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.xlobo.api.fund.parameter.InfoBean;
import com.xlobo.api.fund.parameter.InfoBean2;
import com.xlobo.api.fund.service.InfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.XloboAccountCallService;

/**
 * 获取账户信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_Info {
	private static InfoBean infobean;
	private static InfoCall infocall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据UserID+AccountType获取账户信息");
	}

	@Before
	public void caseUp() {
		infobean = new InfoBean();
		infocall = new InfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(infocall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Info_001() {
		Logger.start(true,"信息输入完整，获取账户信息成功");
		try {
			int AccountType = 0;
			Map<?, ?> map = XloboAccountCallService.getAccount(AccountType);// 生成UserId
			infobean.setUserId((String) map.get("UserId"));

			infobean.setUserAccountType(AccountType);
			infocall.setData(infobean);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(map.get("UserId"), infocall.getUserId(), "UserId返回验证");
			Logger.verifyEquals(AccountType, Integer.valueOf(infocall.getAccountType()), "AccountType返回验证");
			Logger.verifyNotNull(infocall.getAccountId(), "账户ID返回正常");
			Logger.verifyNotNull(infocall.getAvailableAmount(), "账户可用金额");
			Logger.verifyNotNull(infocall.getFreezeAmount(), "账户冻结金额");
			Logger.verifyNotNull(infocall.getTotalAmount(), "账户总金额");
			Logger.verifyNotNull(infocall.getGiftAmount(), "账户赠送金额");
			Logger.verifyNotNull(infocall.getTradingPassword(), "账户交易密码");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Info_002() {
		Logger.start(true,"不输入UserId,获取账户信息失败");
		try {
			/*
			 * String UserId = AccountCallService.getAccount(0);//生成UserId
			 * infobean.setUserId(UserId);
			 */
			infobean.setUserAccountType(0);
			infocall.setData(infobean);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(404, infocall.getStatusCode(), "响应状态404");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_Info_003() {
		Logger.start(true,"不输入AccountType(系统默认0),获取账户信息成功");
		try {
			Map<?, ?> map = XloboAccountCallService.getAccount(0);// 生成UserId
			infobean.setUserId((String) map.get("UserId"));
			// infobean.setUserAccountType(0);
			infocall.setData(infobean);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(200, infocall.getStatusCode(), "响应状态200");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Info_004() {
		Logger.start(true,"AccountType与实际type不一致,获取账户信息失败");
		try {
			Map<?, ?> map = XloboAccountCallService.getAccount(3);// 生成UserId
			infobean.setUserId((String) map.get("UserId"));
			infobean.setUserAccountType(0);
			infocall.setData(infobean);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(400, infocall.getStatusCode(), "响应状态400");
			Logger.verifyEquals("未找到该用户的账户信息", infocall.getErrorMsg(), "校验错误响应信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Info_005() {
		Logger.start(true,"根据AccountId获取账户信息");
		try {
			Map<?, ?> Account = XloboAccountCallService.getAccountId();
			Logger.comment("AccountId" + Account.get("AccountId"));
			infobean.setAccountId((String) Account.get("AccountId"));
			infocall.setData(infobean);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(Account.get("UserId"), infocall.getUserId(), "UserId返回验证");
			Logger.verifyEquals(Account.get("AccountType"), Integer.valueOf(infocall.getAccountType()),
					"AccountType返回验证");
			Logger.verifyNotNull(infocall.getAccountId(), "账户ID返回正常");
			Logger.verifyNotNull(infocall.getAvailableAmount(), "账户可用金额");
			Logger.verifyNotNull(infocall.getFreezeAmount(), "账户冻结金额");
			Logger.verifyNotNull(infocall.getTotalAmount(), "账户总金额");
			Logger.verifyNotNull(infocall.getGiftAmount(), "账户赠送金额");
			Logger.verifyNotNull(infocall.getUserName(), "用户名");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Info_006() {
		Logger.start(true,"不输入AccountId,获取账户信息失败");
		try {
			infocall.setData(infobean);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(404, infocall.getStatusCode(), "响应状态404");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Info_007() {
		Logger.start(true,"根据UserName+AccountType,获取账户信息");
		try {
			InfoBean2 infobean2 = new InfoBean2();
			Map<?, ?> map = XloboAccountCallService.getAccount(3);// 生成UserId
			String UserName = (String) map.get("Uname");
			Logger.comment("UserName" + UserName);
			Integer AccountType = (Integer) map.get("AccountType");
			Logger.comment("AccountType" + AccountType);
			infobean2.setUserName(UserName);
			infobean2.setAccountType(AccountType);
			infocall.setData(infobean2);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(map.get("UserId"), infocall.getUserId(), "UserId返回验证");
			Logger.verifyEquals(map.get("AccountType"), Integer.valueOf(infocall.getAccountType()),
					"AccountType返回验证");
			Logger.verifyEquals(UserName, infocall.getUserName(), "用户名");
			Logger.verifyNotNull(infocall.getAccountId(), "账户ID返回正常");
			Logger.verifyNotNull(infocall.getAvailableAmount(), "账户可用金额");
			Logger.verifyNotNull(infocall.getFreezeAmount(), "账户冻结金额");
			Logger.verifyNotNull(infocall.getTotalAmount(), "账户总金额");
			Logger.verifyNotNull(infocall.getGiftAmount(), "账户赠送金额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_Info_008() {
		Logger.start(true,"根据UserName+AccountType,AccountType为空(默认为0),获取账户信息");
		try {
			InfoBean2 infobean2 = new InfoBean2();
			Map<?, ?> map = XloboAccountCallService.getAccount(0);// 生成UserId
			String UserName = (String) map.get("Uname");
			Logger.comment("UserName" + UserName);
			infobean2.setUserName(UserName);
			infocall.setData(infobean2);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(map.get("UserId"), infocall.getUserId(), "UserId返回验证");
			Logger.verifyEquals(map.get("AccountType"), Integer.valueOf(infocall.getAccountType()),
					"AccountType返回验证");
			Logger.verifyEquals(UserName, infocall.getUserName(), "用户名");
			Logger.verifyNotNull(infocall.getAccountId(), "账户ID返回正常");
			Logger.verifyNotNull(infocall.getAvailableAmount(), "账户可用金额");
			Logger.verifyNotNull(infocall.getFreezeAmount(), "账户冻结金额");
			Logger.verifyNotNull(infocall.getTotalAmount(), "账户总金额");
			Logger.verifyNotNull(infocall.getGiftAmount(), "账户赠送金额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Info_009() {
		Logger.start(true,"根据UserName+AccountType,AccountType与实际不一致,获取账户信息失败");
		try {
			InfoBean2 infobean2 = new InfoBean2();
			Map<?, ?> map = XloboAccountCallService.getAccount(0);// 生成UserId
			String UserName = (String) map.get("Uname");
			Logger.comment("UserName" + UserName);
			Integer AccountType = (Integer) map.get("AccountType");
			Logger.comment("实际AccountType" + AccountType);
			infobean2.setUserName(UserName);
			Logger.comment("传入AccountType" + 3);
			infobean2.setAccountType(3);
			infocall.setData(infobean2);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals("未找到该用户的账户信息", infocall.getErrorMsg(), "错误信息验证");
			Logger.verifyEquals(400, infocall.getStatusCode(), "响应状态验证");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Info_010() {
		Logger.start(true,"根据UserName+AccountType,UserName为空,获取账户信息失败");
		try {
			InfoBean2 infobean2 = new InfoBean2();
			Logger.comment("AccountType" + 0);
			infobean2.setAccountType(0);
			infocall.setData(infobean2);
			infocall.callService();
			Logger.comment("infocall send:" + infocall.getEntityString());
			Logger.comment("infocall response:" + infocall.getReturnData());
			Logger.verifyEquals(404, infocall.getStatusCode(), "响应状态验证");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}